package com.bookstore.interceptor;

import com.bookstore.domain.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user = (User) request.getSession().getAttribute("loginUser");
        if(user != null){ //为空 拦截 否则放行
            return true;
        }
        response.sendRedirect(request.getContextPath() + "/user/login.do");
        return false;
    }
}
